//动态规划
class Solution {
public:
    int LastRemaining_Solution(int n, int m) {
        int f=0;
        for(int i=2;i<=n;i++)
        {
            f=(f+m)%i;
        }
        return f;
    }
};
//模拟
class Solution {
public:
    int LastRemaining_Solution(int n, int m) {
        vector<int> v(n);
        for(int i=0;i<n;i++)
        v[i]=i;
        int ret=n;
        int k=0;//报数
        int x=0;//索引人
        while(ret!=1)
        {
            if(k==m-1)
            {
                v[x]=-1;
                ret--;
                k=-1;
            }
            k++;
            x++;
            x%=n;
            while(v[x]==-1)
            {
                x++;
                x%=n;
            }
        }
        return v[x];
    }
};